<?php

if (isset($_FILES['Filedata']) and $_FILES['Filedata']['error'] == 0) {	
	$sort = $db->fetchOne("SELECT MAX(sort) FROM cms_images WHERE folder_id=?", $_SESSION['image_folder_id']) + 10;
	$db->insert('cms_images', array(
		'site_id'   => $site['id'],
		'folder_id' => $_SESSION['image_folder_id'],
		'filename'  => $_FILES['Filedata']['name'],
		'mime_type' => $_FILES['Filedata']['type'],
		'data'      => file_get_contents($_FILES['Filedata']['tmp_name']),
		'size'      => $_FILES['Filedata']['size'],
		'created'   => new Zend_Db_Expr('NOW()'),
		'modified'  => new Zend_Db_Expr('NOW()'),
		'sort'      => $sort
	));
	
}

echo "OK\n";
